package com.xyoto.takeawayBusiness.controller;

import com.xyoto.takeawayBusiness.aspect.annotation.RequiresLogin;
import com.xyoto.takeawayBusiness.dto.MenuTypeDTO;
import com.xyoto.takeawayBusiness.dto.SaveShoppingDto;
import com.xyoto.takeawayBusiness.dto.UpdateShoppingDto;
import com.xyoto.takeawayBusiness.dto.UpdateTypeDTO;
import com.xyoto.takeawayBusiness.service.ShoppingAttributeService;
import com.xyoto.takeawayBusiness.service.ShoppingGoodsService;
import com.xyoto.takeawayBusiness.service.ShoppingService;
import com.xyoto.takeawayBusiness.service.ShoppingTypeService;
import com.xyoto.takeawayBusiness.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @Description
 * @Author: TingFeng
 * @CreateTime: 2022/4/26  19:08
 */
@Api(tags = "菜单")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private ShoppingService shoppingService;

    @Autowired
    private ShoppingTypeService shoppingTypeService;

    @Autowired
    private ShoppingAttributeService shoppingAttributeService;

    @Autowired
    private ShoppingGoodsService shoppingGoodsService;

    @RequiresLogin
    @ApiOperation("新增菜单分类")
    @PostMapping("/addType")
    public Result addType(@RequestBody @Valid MenuTypeDTO menuTypeDTO){
        return shoppingTypeService.addType(menuTypeDTO);
    }

    @RequiresLogin
    @ApiOperation("获取菜单分类 ")
    @GetMapping("/getMenu")
    public Result getMenu(
            @NotNull(message = "商铺id不能为空")
            @Min(value = 0,message = "最小为0")
            @RequestParam("shopId") Integer shopId){
        return shoppingTypeService.getMenu(shopId);
    }

    @RequiresLogin
    @ApiOperation("修改菜单分类")
    @PostMapping("/updateType")
    public Result updateType(@RequestBody @Valid UpdateTypeDTO updateTypeDTO){
        return shoppingTypeService.updateType(updateTypeDTO);
    }

    @RequiresLogin
    @ApiOperation("删除菜单分类")
    @DeleteMapping("/removeType")
    public Result removeType(
            @NotNull(message = "菜单分类id不能为空")
            @Min(value = 0,message = "最小为0")
            @RequestParam("menuId") Integer menuId){
        return shoppingTypeService.removeType(menuId);
    }
    @GetMapping("/getShop")
    @ApiOperation("获取商铺页")
    @RequiresLogin
    public Result getShop(
            @NotNull(message = "商铺id不能为空")
            @Min(value = 0,message = "最小为0")
            @RequestParam("shopId") Integer shopId){
        return shoppingTypeService.getShop(shopId);
    }

    @RequiresLogin
    @PostMapping("/addShopping")
    @ApiOperation(value = "新增商品", notes = "添加新的商品信息")
    public Result addShopping(SaveShoppingDto saveDto){
        return shoppingService.addShopping(saveDto);
    }

    @RequiresLogin
    @PostMapping("/updateShopping")
    @ApiOperation(value = "修改商品", notes = "修改商品信息")
    public Result updateShopping(UpdateShoppingDto updateDto){
        return shoppingService.updateShopping(updateDto);
    }

    @RequiresLogin
    @DeleteMapping("/removeSpec")
    @ApiOperation(value = "删除规格", notes = "删除商品规格")
    public Result removeSpec(@Valid @NotNull(message = "规格id不能为空") @RequestParam("id") Integer id){
        return shoppingGoodsService.removeGoods(id);
    }

    @RequiresLogin
    @DeleteMapping("/removeProd")
    @ApiOperation(value = "删除属性", notes = "删除商品属性")
    public Result removeProd(@Valid @NotNull(message = "属性id不能为空") @RequestParam("id") Integer id){
        return shoppingAttributeService.removeProd(id);
    }

    @RequiresLogin
    @DeleteMapping("/removeShopping")
    @ApiOperation(value = "删除商品", notes = "删除商品")
    public Result removeShopping(@Valid @NotNull(message = "商品id不能为空") @RequestParam("id") Integer id){
        return shoppingAttributeService.removeShopping(id);
    }
}
